package com.briup.bookstore.service.impl;

import com.briup.bookstore.dto.BookSearchDTO;
import com.briup.bookstore.mapper.BookMapper;
import com.briup.bookstore.mapper.CollectMapper;
import com.briup.bookstore.po.Book;
import com.briup.bookstore.po.Collect;
import com.briup.bookstore.po.ext.BookExtend;
import com.briup.bookstore.service.BookService;
import com.briup.bookstore.utils.BeanCopyUtils;
import com.briup.bookstore.vo.BookInfoVO;
import com.briup.bookstore.vo.BookVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookMapper bookMapper;

    @Autowired
    CollectMapper collectMapper;

    public BookInfoVO getBookById(Integer bookId, Integer userId) {
        Book book = bookMapper.selectById(bookId);
        BookInfoVO bookInfoVO = BeanCopyUtils.copyBean(book, BookInfoVO.class);
        // 详细信息中包括了当前用户是否收藏了该书籍
        // 查询当前书本是否被当前用户所收藏
        Collect collect = collectMapper.selectByBookIdAndUserId(bookId, userId);
        bookInfoVO.setCollect(!Objects.isNull(collect));

        return bookInfoVO;
    }

    public BookInfoVO getBookById(Integer bookId) {
        return null;
    }

    public PageInfo<BookExtend> getPageBook(Integer pageNum, Integer pageSize, BookSearchDTO bookSearchDTO) {
        return null;
    }

    public List<BookVO> getBook(String query) {
        return null;
    }

    public void saveBook(Book book) {

    }

    public void modifyBook(Book book) {

    }

    public void removeBook(Integer id) {

    }

    public void modifyStatus(Integer id, Integer status) {

    }

    public void removeBatchByIds(List<Integer> ids) {

    }

    public List<BookVO> getBooksByCategoryId(Integer categoryId) {
        return null;
    }

    public List<BookVO> showBooks() {
        List<BookExtend> bookExtends = bookMapper.selectBookBefore20();
        return BeanCopyUtils.copyBeanList(bookExtends, BookVO.class);
    }

    public Book showBookById(Integer id) {
        return null;
    }
}
